<template>
  <div>
    <el-row>
      <div class="block">
        <span class="demonstration"> 创建时间 </span>
        <el-date-picker
          v-model="value1"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
    </el-row>
    <el-row style="margin: 10px 0">
      <el-button type="primary" plain size="mini" @click="addlist">
        <i class="el-icon-plus"></i> 新增</el-button
      >
      <el-button type="success" plain size="mini">
        <i class="el-icon-edit"></i> 修改</el-button
      >
      <el-button type="danger" plain size="mini">
        <i class="el-icon-delete"></i> 删除</el-button
      >
      <el-button type="warning" plain size="mini">
        <i class="el-icon-download"></i> 导出</el-button
      >
    </el-row>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column prop="id" label="角色编号" width="120"></el-table-column>
      <el-table-column
        prop="name"
        label="角色名称"
        width="250"
      ></el-table-column>
      <el-table-column
        prop="role"
        label="权限字符"
        width="250"
      ></el-table-column>

      <el-table-column label="状态" width="200">
        <template slot-scope="scope">
          <el-switch
            v-model="value"
            active-color="#70b9fd"
            inactive-color="#ff4949"
          >
          </el-switch>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" width="250">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="margin: 30px 20px; float: right">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
        background
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nameinput: "",
      tableData: [
        {
          id: 1,
          name: "超级管理员",
          role: "admin",
          date: "2021-05-02",
        },
        {
          id: 2,
          name: "普通角色",
          role: "common",
          date: "2021-05-04",
        },
      ],
      value: true,
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 1,
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
      confirm("是否确认修改!")
    },
    handleDelete(index, row) {
      console.log(index, row);
      this.tableData.splice(index,1)
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style lang="scss" scoped>
el-input{
  display: inline-block;
}
.has-gutter {
  background-color: #f8f8f9;
}
</style>